import Taro, {Component} from '@tarojs/taro'
import { View, ScrollView } from '@tarojs/components'
import classNames from 'classnames'
import styles from './index.module.scss'
import {getCount} from "@/api/productApi";

interface IProps {
  current: number
  onClick: Function
  className: string
  info: Object
  scroll: any
}

export default class TabList extends Component<IProps, {}> {
  state: any
  props: any
  static options = {
    addGlobalClass: true
  }

  constructor(props) {
    super(...arguments)
    // this.setState({
    //   tabKey: props.current || 0
    // })
    this.state = {
      tabKey: props.current || 0
    }
  }
  componentDidMount() {
  }

  //  切换tab
  onSwitchTab(k, tab) {
    const { onClick } = this.props
    this.setState({
      tabKey: k
    })
    if (onClick) {
      onClick(k, tab)
    }
  }

  render() {
    const { info } = this.props
    const { tabKey } = this.state
    return (<ScrollView scrollX className={classNames(styles.tabList)}>
      <View className={classNames(styles.tabListItem, 'f-g-5', tabKey === 'recommend' && styles.typeItemActive)} onClick={this.onSwitchTab.bind(this, 'recommend')}>{info.head}</View>
      {info.list.map((tab) => {
        return (<View key={tab.id} className={classNames( styles.tabListItem, 'f-g-5', tabKey === tab.id && styles.typeItemActive)} onClick={this.onSwitchTab.bind(this, tab.id, tab)}>{tab.name}</View>)
      })}
    </ScrollView>)
  }
}
